<template>
	<view class="overhide" v-if="getList().length>0">
		<view class="book_list book_list_1" :style="'margin-top:'+marTop+'rpx'" v-if="type==1">
			<view class="title" v-if="title">{{title}}</view>
			<view class="list">
				<view class="lis flex" v-for="(item,index) in getList()">
					<view :class="['li',index==0?'list_1':'']" v-for="items in item" @tap="detailUrl(items.url)">
						<view class="cover">
							<up-image width="155rpx" height="206rpx" radius="8rpx" :src="items.img"></up-image>
						</view>
						<view class="info flex-col">
							<view class="btitle">
								<view class="t u-line-1">{{items.title}}
								</view>
								<view class="score" v-if="index==0">{{items.score}}</view>
							</view>
							<view class="bdesc" v-if="index==0">
								<view class="u-line-2">{{items.about}}</view>
							</view>
							<view class="bauthor">
								<view class="a">{{items.bookAuthor}}</view>
								<view class="bookTags" v-if="index==0">
									<view class="tag" v-for="tag in items.tags">{{tag}}</view>
								</view>
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="book_list book_list_2" :style="'margin-top:'+marTop+'rpx'" v-else-if="type==2">
			<view class="title" v-if="title">{{title}}</view>
			<view class="list list_1" v-for="items in list" @tap="detailUrl(items.url)">
				<view class="cover">
					<up-image width="155rpx" height="206rpx" radius="8rpx" :src="items.img"></up-image>
				</view>
				<view class="info flex-col">
					<view class="btitle">
						<view class="t u-line-1">{{items.title}}</view>
						<view class="score">{{items.score}}</view>
					</view>
					<view class="bdesc">
						<view class="u-line-2">{{items.about}}</view>
					</view>
					<view class="bauthor">
						<view class="a">{{items.bookAuthor}}</view>
						<view class="bookTags">
							<view class="tag" v-for="tag in items.tags">{{tag}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="book_list book_list_3" :style="'margin-top:'+marTop+'rpx'" v-else-if="type==3">
			<view class="title" :style="{'font-size':titleSize+'px'}" v-if="title">{{title}}</view>
			<view class="list overhide">
				<view class="li" v-for="(item,index) in list" @tap="detailUrl(item.url)">
					<up-image width="155rpx" height="206rpx" radius="8rpx" :src="items.img"></up-image>
					<view class="btitle">
						<view class="t u-line-1">{{item.title}}</view>
					</view>
					<view class="bauthor">
						<view class="a">{{item.bookAuthor}}</view>
					</view>
				</view>
			</view>
		</view>
		<view class="book_list" :style="'margin-top:'+marTop+'rpx'" v-else-if="type==4">
			<view class="title" v-if="title">{{title}}</view>
			<view class="rank_list flex">
				<view class="rli flex" v-for="(item,index) in list" @tap="detailUrl(item.url)">
					<view class="topWrap flex-ju-al">
						<image class="top" :src="'../../static/img/com/tops'+(index+1)+'.webp'" v-if="index<3"></image>
						<view class="top flex-ju-al" v-else>{{index+1}}</view>
					</view>
					<view class="cover">
						<up-image width="150rpx" height="200rpx" radius="8rpx" :src="item.img"></up-image>
					</view>
					<view class="info flex-col">
						<view class="title u-line-1 blocks">{{item.title}}</view>
						<view class="author flex">
							<view class="a u-line-1 blocks">{{item.bookAuthor}}</view>
							<view class="t u-line-1 blocks" v-if="item.tags.length>0">
								{{item.tags[0]}}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	const props =defineProps({
		title: {
			type: String,
			default: ''
		},
		titleSize: {
			type: [String, Number],
			default: 16
		},
		type: {
			type: [String, Number],
			default: 0 // 1:1/3-2:1-3:2/4--4:榜单
		},
		marTop: {
			type: [String, Number],
			default: 60
		},
		list: {
			type: Array,
			default: []
		}
	})
	const coverStyle = ref({
		w: '155rpx',
		h: '206rpx',
		r: '8rpx'
	})
	const rankCover = ref({
		w: '150rpx',
		h: '200rpx',
		r: '8rpx'
	})
	
	const getList = ()=>{
		let data = props.list
		let result = []
		let result1 = []
		data.forEach((item, index) => {
			if (index == 0) {
				result.push(item)
			} else {
				result1.push(item)
			}
		})
		return [result, result1]
	}
	
	const detailUrl = (url)=> {
		uni.$pageJump(url)
	}
</script>

<style lang="scss" scoped>
	.book_list {

		.title {
			color: #090909;
			font-size: 32rpx;
			font-weight: bold;
		}

		.list {
			margin-top: 30rpx;

			.score {
				color: #FE3F3F;
				font-size: 28rpx;
				font-weight: bold;
			}

			.cover {
				width: 155rpx;
				height: 206rpx;
				border-radius: 8rpx;
			}

			.btitle {
				color: #090909;
				font-weight: bold;
				font-size: 28rpx;
				margin-top: 6rpx;
			}

			.bdesc {
				color: #6F6F6F;
				font-size: 22rpx;
				margin-top: 20rpx;
			}

			.bauthor {
				// margin-top: 4rpx;

				.a {
					color: #6F6F6F;
					font-size: 22rpx;
				}
			}


			&_1 {
				display: flex;
				height: 206rpx;

				.info {
					width: 0;
					margin-left: 25rpx;
					display: flex;
					flex: 1 0 auto;
					flex-direction: column;

					.btitle {
						display: flex;
						justify-content: space-between;
					}

					.bauthor {
						margin-top: auto;
						margin-bottom: 10rpx;
						display: flex;
						align-items: center;
						justify-content: space-between;
					}

					.btitle {
						.t {
							width: 0;
							flex: 1 0 auto;
						}
					}
				}
			}
		}

		&_1 {

			.list {
				.lis {
					.li {
						flex: 1;

						&:nth-child(n+2) {
							margin-left: 25rpx;
						}
					}

					&:last-child {
						margin-top: 30rpx;

						.info {
							padding: 0 8rpx;
						}
					}
				}
			}
		}

		&_3 {
			.li {
				width: 155rpx;
				float: left;
				margin-left: 25rpx;

				&:nth-child(4n+1) {
					margin-left: 0;
				}

				&:nth-child(n+5) {
					margin-top: 30rpx;
				}
			}
		}
	}

	.rank_list {
		overflow-x: scroll;
		overflow-y: hidden;
		white-space: nowrap;
		font-size: 0;
		line-height: 0;
		vertical-align: bottom;
		height: 690rpx;
		flex-flow: column wrap;

		.rli {
			width: 74%;
			height: 200rpx;
			margin-top: 0;
			margin-top: 30rpx;
			line-height: initial;

			.topWrap {
				width: 80rpx;

				.top {
					width: 54rpx;
					height: 54rpx;
					color: #BEBEBE;
					font-size: 32rpx;
					font-weight: bold;
				}
			}

			.cover {
				width: 150rpx;
				height: 100%;
				border-radius: 8rpx;
			}

			.info {
				width: 0;
				flex: 1 0 auto;
				margin-left: 30rpx;
				padding: 28rpx 0;

				.author {
					font-size: 22rpx;
					color: #6F6F6F;
					margin-top: auto;

					.a {
						max-width: 50%;
					}

					.t {
						padding-left: 28rpx;
						box-sizing: border-box;
						max-width: 50%;
					}
				}
			}
		}
	}
</style>